<template>
	<view>
		<view class="justify-center" style="margin-bottom: 30px;margin-top: 30px;">
			<view>
				<image :src="store.mer_avatar" class="mer-img"></image>
			</view>
			<view class="title">
				{{store.mer_name}}
			</view>
		</view>
		<fx-amountInput :confirmText="confirmText" :btnColor="btnColor" 
		:placeholder="placeholder" :maxNumber="maxNumber" :isBold="isBold" :isFilter="isFilter" 
		@change="change" @confirm="confirm" :store="store"></fx-amountInput>
		<authorize @onLoadFun="onLoadFun" :isAuto="isAuto" :isShowAuth="isShowAuth" @authColse="authColse"></authorize>
	</view>
</template>

<script>
	
	
	import fxAmountInput from '@/components/fx-amountInput/fx-amountInput.vue';
	import { HTTP_REQUEST_URL } from '@/config/app'
	import {getStoreDetail} from '@/api/store.js';
	import shareScence from "@/libs/spread";
	import authorize from '@/components/Authorize';
	import { configMap } from "@/utils";
	import { mapGetters } from "vuex";
	import { getUserInfo } from '@/api/user.js';
		import request from "@/utils/request.js";
		import {
			getProductDetail,
			postCartAdd,
		} from '@/api/store.js';
	export default {
	    components: {
	        fxAmountInput,
			authorize
	    },
		data() {
			return {
				price: '',
				mer_id: 0,
				store:'',
				maxNumber: 10000,
				placeholder:'请输入付款金额',
				confirmText:'优惠买单',
				isBold:true,
				isFilter:true,
				btnColor:'#FF5C2D',
				currSpid: "",
				isShowAuth: false, //是否隐藏授权
				isAuto: false, //没有授权的不会自动授权
				domain: HTTP_REQUEST_URL,
				type:1,
				id:0
			}
		},
		computed: {
			...configMap({
				margin_ico_switch: 0,
				margin_ico: '',
			}, 
			mapGetters(['isLogin','uid','viewColor','keyColor'])),
		},
		onLoad: function(options) {
			
			this.id = options.mer_id;
			let that = this
			if (options.spid) {
				this.currSpid = options.spid
				app.globalData.spid = options.spid;
			}
			// #ifdef MP
			if (options.scene) {
				let value = this.$util.getUrlParams(decodeURIComponent(options.scene));
				if (value.id ) this.id = value.id || 0;
				//记录推广人uid
				if (value.spid) {
					this.currSpid = value.spid
					app.globalData.spid = value.spid;
				}
			}
			// #endif
			
			if (this.isLogin) {
				this.getStore();
			} else {
				setTimeout(function(){
					that.isAuto = true;
					that.isShowAuth = true
				},1500)
			}
			shareScence(this.currSpid, this.isLogin)
		},
		methods:{
			// 授权回调
			onLoadFun: function() {
				this.isShowAuth = false;
				this.getStore();
			},
			// 授权关闭
			authColse: function(e) {
				this.isShowAuth = e
				uni.switchTab({
					url: '/pages/index/index'
				});
			},
			confirm(e){
				let q = {
					is_new: 1,
					product_id: this.store.store_spu.product_id,
					cart_num: 1,
					product_attr_unique: this.store.store_spu.unique,
					source: '',
					product_type: 0,
					spread_id: this.currSpid,
					syt_price:e,
					is_mer_goods:1
				};
				postCartAdd(q)
					.then(function(res) {
						let cartId = res.data.cart_id
						uni.navigateTo({
							url: '/pages/users/order_confirm/index?is_syt=1&cartId=' + cartId + '&syt_price=' + q.syt_price
						});
					})
					.catch(res => {
						return that.$util.Tips({
							title: res
						});
					});
			},
			change(e){
				
			},
			// 获取商品详情
			getStore: function() {
				getStoreDetail(this.id).then(res => {
					this.store = res.data;
				}).catch(err => {
					this.loading = false;
					uni.showToast({
						title: err,
						icon: 'none'
					})
				})
			},
		}
	}
</script>

<style>
	.mer-img {
		width: 80px;
		    height: 80px;
		    border-radius: 50%;
		    margin: auto;
		    display: block;
	}
	.title {
		text-align: center;
		    font-weight: 600;
		    margin-top: 10px;
	}
</style>